package com.coderlin.dao.role;

import com.coderlin.dao.BaseDao;
import com.coderlin.pojo.Role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * <Description> <br>
 *
 * @author Coder_Lin<br>
 * @version 1.0<br>
 * @taskId: <br>
 * @createDate 2021/03/14 19:45 <br>
 * @see com.coderlin.dao.role <br>
 */
public class RoleDaoImpl implements RoleDao{

    @Override
    public List<Role> getRoleList(Connection connection) throws SQLException {
        PreparedStatement pstm = null;
        ResultSet rs = null;
        ArrayList<Role> list = new ArrayList<>();

        if(connection!=null){
            String sql = "SELECT * FROM smbms_role";
            Object[] params = {};
            rs = BaseDao.excute(connection, pstm, rs, sql, params);

            while(rs.next()){
                Role role = new Role();
                role.setId((long) rs.getInt("id"));
                role.setRolename(rs.getString("roleName"));
                role.setRolecode(rs.getString("roleCode"));
                list.add(role);
            }
        }
        BaseDao.closeResource(null,pstm,rs);
        return list;
    }
}
